import React, { Component } from 'react'
import './index.css'

export default class Footer extends Component {
	isChecked = false
	handleChangeAll = (e) => {
		const done = e.target.checked
		this.props.checkedAll(done)
	}
	handleClearDone = () => {
		this.props.clearDone()
	}
	render() {
		const {todos} = this.props
		// 已完成的个数
		const countDone = todos.reduce((pre, todo) => {
			return pre + (todo.done ? 1 : 0)
		}, 0)
		const total = todos.length
		// 总数
		return (
			<div className="footer flex flex-row justify-between align-center">
				<div>
					<input type="checkbox" onChange={this.handleChangeAll} checked={countDone === total && total !== 0 ? true : false}/>
					<label style={{marginLeft: '20px'}}>
						<span>已经完成{countDone}</span>
						/
						<span>全部{total}</span>
					</label>
				</div>
				<button className="btn clear-btn" onClick={this.handleClearDone}>清除已完成任务</button>
			</div>
		)
	}
}
